export const regular = {
  // 密码复杂度
  pwdComplexity1: /^(?=.*[A-Za-z])(?=.*\d)(?=.*[~!@#$%^&*()_+}{":?><*,./;'`])[A-Za-z\d~!@#$%^&*()_+}{":?><*,./;'`]{8,}$/,
  pwdComplexity2: /^(?![\d]+$)(?![a-zA-Z]+$)[\da-zA-Z]{8,18}$/,
  // 身份证
  idCard: /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
  // 出生日期
  birthday: /^((19[2-9]\d{1})|(20(([0-9][0-9])|(1[0-8]))))\-((0?[1-9])|(1[0-2]))\-((0?[1-9])|([1-2][0-9])|30|31)$/,
  // 手机号码
  phone: /^1[3-9]\d{9}$/,
  // 邮箱
  email: /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
  // 非特殊字符
  specialChar: !/[(\ )(\~)(\!)(\@)(\#) (\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=) (\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/) (\<)(\>)(\?)(\)]+/,
  // 邮政编码（6位数字）
  postCode: /^[1-9]\d{5}$/,
  // 学籍号校验(9位数字)
  stuNumber: /^[1-9]\d{8}$/,
  // 全国学籍号(首位为大写字母+18位字符)
  countryNumber: /^[A-Z][A-Za-z0-9]\w{17}$/,
  // 联系电话（数字、横杠）
  tel: /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/,
  // 整数或者小数（不小于0）
  noLessThanZero: /^[0-9]+([.][0-9]+){0,1}$/,
  // 正整数
  positiveInteger: /^\+?[1-9][0-9]*$/,
  // 正整数和0
  naturalNumber: /^([1-9]\d*|[0]{1,1})$/,
  // 数字用逗号隔开 如 10,12,30
  numSeparatedByCommas: /^\d+?(?:,\d+?)*$/,
  // 网站地址
  website: /^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/,
  // 大于0的数字，可保留1位小数
  keepOneDecimal: /^[0-9]+([.][0-9]?){0,1}$/
}

const commonRules = {
  aa: [
    { required: true, message: "请输入登录名" },
    { max: 20, message: "名称不得超过20个字符" },
    {
      pattern: new RegExp("^[0-9a-zA-Z_]{1,}$", "g"),
      message: "只允许包含数字、字母、下划线"
    },
    {
      validator: (rule, value, callback) => {
        if (value.length >= 6 && value.length <= 10) {
          return Promise.resolve()
        }
        return Promise.reject(new Error("密码长度必须是6~10位"))
      }
    }
  ]
}

const systemRules = {
  deptId: [{ required: true, message: "归属机构不能为空" }],
  nickName: [{ required: true, message: "用户昵称不能为空" }],
  userName: [{ required: true, message: "用户名称不能为空" }],

  roleName: [{ required: true, message: "角色名称不能为空" }],
  roleKey: [{ required: true, message: "权限字符不能为空" }],

  deptName: [{ required: true, message: "机构名称不能为空" }],
  deptCode: [{ required: true, message: "机构编码不能为空" }],
  parentId: [{ required: true, message: "上级机构不能为空" }],

  menuName: [{ required: true, message: "菜单名称不能为空" }],
  orderNum: [{ required: true, message: "菜单顺序不能为空" }],
  path: [{ required: true, message: "路由地址不能为空" }],

  postName: [{ required: true, message: "岗位名称不能为空" }],
  postCode: [{ required: true, message: "岗位编码不能为空" }],

  dictTypeName: [{ required: true, message: "字典名称不能为空" }],
  dictType: [{ required: true, message: "字典类型不能为空" }],

  configName: [{ required: true, message: "参数名称不能为空" }],
  configKey: [{ required: true, message: "参数键名不能为空" }],
  configValue: [{ required: true, message: "参数键值不能为空" }]
}

const rules = {
  system: systemRules
}

export const getRules = (module: string, keys: string[]): any[] => {
  return keys.map((key) => ({
    [key]: rules[module][key] || commonRules[key] || []
  }))
}
